package com.example.service.impl;

import com.example.mapper.UserMapper;
import com.example.pojo.Change;
import com.example.pojo.Result;
import com.example.pojo.User;
import com.example.service.UserService;
import com.example.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public User login(User user) {
        User user1=userMapper.login(user);
        return user1;
    }

    @Override
    public void register(User user) {
        userMapper.register(user);
    }

    @Override
    public String getPasswords(HttpServletRequest request) {
        String passwords=userMapper.getPasswords(JwtUtils.parseJWT(request.getHeader("token")).get("id", Integer.class));
        return passwords;
    }

    @Override
    public void changeMm(Change change, HttpServletRequest request) {
        User user=new User();
        user.setId(JwtUtils.parseJWT(request.getHeader("token")).get("id", Integer.class));
        user.setPasswords(change.getPasswordsOne());
        userMapper.setChangeMm(user);
    }

    @Override
    public User getPim(HttpServletRequest request) {
        User user=userMapper.getPim(JwtUtils.parseJWT(request.getHeader("token")).get("id", Integer.class));
        return user;
    }

    @Override
    public void setPim(User user, HttpServletRequest request) {
        user.setId(JwtUtils.parseJWT(request.getHeader("token")).get("id", Integer.class));
        userMapper.setPim(user);
    }


    @Override
    public void insertUser(User user) {
        userMapper.insert(user);
    }

    @Override
    public User getphone(String account) {
        User user=userMapper.getphone(account);
        return user;
    }


}
